package controller

import (
	. "api/model"
	"net/http"
	"github.com/gin-gonic/gin"
)

type PersonInfo struct {
	Name  string `json:"name"`
	Token string `json:"token"`
}

func GetIncomePay(c *gin.Context) {
	i := IncomePay{}
	ret, err := i.GetIncomePay()
	if err != nil {
		c.JSON(http.StatusOK, gin.H{"error": err.Error()})
		return
	}

	c.JSON(http.StatusOK, gin.H{"status": 200, "msg": "success", "data": ret})
}

func SyserLogin(c *gin.Context) {
	s := Syser{}

	err := c.BindJSON(&s)
	if err != nil {
		c.JSON(http.StatusOK, gin.H{"error": err.Error()})
	}

	token, err := s.SyserLogin(s.Name, s.Password)
	if err != nil {
		c.JSON(http.StatusOK, gin.H{"error": err.Error()})
		return
	}

	c.JSON(http.StatusOK, gin.H{"status": 200, "msg": "success", "data": PersonInfo{s.Name, token}})
}